using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class PlayerStateMachine : StateMachine
{
    /*************************状态信息***************************/
    //PlayerState资源文件
    [SerializeField] PlayerState[] states;
    /*************************标准组件***************************/
    Animator animator;                                                       // 获取动画组件
    Rigidbody2D my_Body2D;                                                   // 获取刚体组件
    BoxCollider2D playerBox2D;                                               // 玩家碰撞盒子
    /*************************控制组件***************************/
    PlayerControl playerControl;                                             // 控制玩家移动
    PlayerStatusInformation playerStatusInformation;                         // 玩家状态信息
    [SerializeField] GameObject playerFoot;                                  // 玩家的脚
    /*************************控制检测***************************/
    PlayerInput playerInput;                                                 // 输入检测
    PlayerDetection playerDetection;                                         // 射线检测
    void Awake()
    {
        /*************************状态信息组件***************************/
        stateTable = new Dictionary<System.Type, IState>(states.Length);                           // 初始化字典
        /*************************标准组件***************************/
        animator = GetComponent<Animator>();                                                       // 获取动画组件
        my_Body2D = GetComponent<Rigidbody2D>();                                                   // 获取刚体组件
        playerBox2D = GetComponent<BoxCollider2D>();                                               // 玩家碰撞盒子
        /*************************控制组件***************************/
        playerControl = GetComponent<PlayerControl>();                                             // 控制玩家移动
        playerStatusInformation = GetComponent<PlayerStatusInformation>();                         // 状态信息
        /*************************控制检测***************************/
        playerInput = GetComponent<PlayerInput>();                                                 // 输入组件
        playerDetection = GetComponent<PlayerDetection>();
        //迭代器循环获取状态
        foreach (PlayerState state in states)
        {
            state.Initiatize(
            animator, my_Body2D, playerBox2D,
            playerControl, playerStatusInformation, playerFoot,
            playerInput, playerDetection,
            this);//将动画组件，刚体组件以及PlayerStateMachine传入进去
            //状态存入字典
            stateTable.Add(state.GetType(), state);
        }
    }
    private void Start()
    {//在开始时执行Idle，进入Idle状态
        SwitchOn(stateTable[typeof(PlayerState_Spawn)]);
    }
}